package com.lzy.mall.ware.controller;


import cn.hutool.core.collection.CollUtil;
import com.lzy.mall.common.utils.PageUtils;
import com.lzy.mall.common.utils.ResultUtils;
import com.lzy.mall.ware.dao.WmsPurchaseDao;
import com.lzy.mall.ware.entity.WmsPurchase;
import com.lzy.mall.ware.entity.WmsPurchaseDetail;
import com.lzy.mall.ware.service.WmsPurchaseService;
import com.lzy.mall.ware.vo.MergeVo;
import com.lzy.mall.ware.vo.PurchaseDoneVo;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * 采购信息(WmsPurchase)表控制层
 *
 * @author lzy
 * @since 2021-08-24 19:01:41
 */
@RestController
@RequestMapping("purchase")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class WmsPurchaseController {
    private final WmsPurchaseService purchaseService;

    /**
     * 完成采购
     */
    @PostMapping("/done")
    public ResultUtils finish(@RequestBody PurchaseDoneVo purchaseDoneVo){
        purchaseService.done(purchaseDoneVo);
        return ResultUtils.ok();
    }

    /**
     * 采购人员app领取采购单
     * @param ids
     * @return
     */
    @PostMapping("/received")
    public ResultUtils received(@RequestBody Long[] ids){
        purchaseService.received(ids);
        return ResultUtils.ok();
    }

    @GetMapping("/list")
    public ResultUtils list(@RequestParam Map<String,Object> params){
        PageUtils page = purchaseService.queryPage(params);
        return ResultUtils.ok().put("page",page);
    }
    //unreceive/list
    @GetMapping("/unreceive/list")
    public ResultUtils Unreceivelist(@RequestParam Map<String,Object> params){
        PageUtils page = purchaseService.queryPageUnreceive(params);
        return ResultUtils.ok().put("page",page);
    }

    //merge
    @RequestMapping("/merge")
    public ResultUtils merge(@RequestBody MergeVo mergeVo){
        purchaseService.mergePurchase(mergeVo);
        return ResultUtils.ok();
    }

    @RequestMapping("/info/{id}")
    //@RequiresPermissions("ware:wareinfo:info")
    public ResultUtils info(@PathVariable("id") Long id){
        WmsPurchase wmsPurchase = purchaseService.getById(id);

        return ResultUtils.ok().put("purchase", wmsPurchase);
    }

    @PostMapping("/save")
    public ResultUtils save(@RequestBody WmsPurchase purchase){
        purchaseService.save(purchase);
        return ResultUtils.ok();
    }

    @PostMapping("/update")
    public ResultUtils update(@RequestBody WmsPurchase purchase){
        purchaseService.update(purchase);
        return ResultUtils.ok();
    }

    @PostMapping("/delete")
    public ResultUtils delete(@RequestBody Long[] ids){
        purchaseService.removeBatch(CollUtil.toList(ids));
        return ResultUtils.ok();
    }

}
